Copy Data places tab-separated values on the clipboard so they can be pasted directly into Excel.
This web application was developed with AI assistance for NTHU General Physics Laboratory. Program development: Lab Maker Project.
Arduino Example Program
/*
Photogate Timer for NTHU General Physics Laboratory.
This program uses two photogates (Gate A and Gate B) to measure the motion of an object.
For each photogate, the program records:
1. Time: the midpoint time of the blocking interval (s)
2. Δt: the duration that the photogate is blocked (s)
Output example:
Gate A: 1.253426, 0.018532
Gate B: 1.684720, 0.017916
The blocking duration Δt can be used to calculate the speed if the length of the blocking object is known.
*/
int gatePinA = 2; // Photogate A: digital pin 2
int gatePinB = 3; // Photogate B: digital pin 3
int ledPin = 13; // Built-in LED
int gatemode = LOW; // LOW when the photogate is blocked. Change to HIGH if needed.
unsigned long t0; // Starting time
unsigned long tNew, tLast; // Entering and leaving times
float time, deltat; // Midpoint time and blocking duration (s)
void setup() {
Serial.begin(115200); // Start serial communication
pinMode(gatePinA, INPUT); // Gate A as input
pinMode(gatePinB, INPUT); // Gate B as input
pinMode(ledPin, OUTPUT); // LED as output
t0 = micros(); // Set the starting time
}
void loop() {
// Gate A
if (digitalRead(gatePinA) == gatemode) { // Gate A is blocked
tNew = micros(); // Object enters Gate A
digitalWrite(ledPin, HIGH); // LED on
while (digitalRead(gatePinA) == gatemode) { ; } // Wait until object leaves
tLast = micros(); // Object leaves Gate A
deltat = (tLast - tNew) / 1000000.0; // Blocking duration (s)
time = (tNew - t0) / 1000000.0 + deltat / 2.0; // Midpoint time (s)
digitalWrite(ledPin, LOW); // LED off
Serial.print("Gate A: ");
Serial.print(time, 6); // Midpoint time (s)
Serial.print(", ");
Serial.println(deltat, 6); // Blocking duration (s)
}
// Gate B
if (digitalRead(gatePinB) == gatemode) { // Gate B is blocked
tNew = micros(); // Object enters Gate B
digitalWrite(ledPin, HIGH); // LED on
while (digitalRead(gatePinB) == gatemode) { ; } // Wait until object leaves
tLast = micros(); // Object leaves Gate B
deltat = (tLast - tNew) / 1000000.0; // Blocking duration (s)
time = (tNew - t0) / 1000000.0 + deltat / 2.0; // Midpoint time (s)
digitalWrite(ledPin, LOW); // LED off
Serial.print("Gate B: ");
Serial.print(time, 6); // Midpoint time (s)
Serial.print(", ");
Serial.println(deltat, 6); // Blocking duration (s)
}
}